<?php

namespace app\admin\controller\data;

use app\admin\model\DataStoreLottery;
use app\admin\model\DataUserReal;
use app\common\controller\AdminController;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use think\App;

/**
 * @ControllerAnnotation(title="data_user_lottery_log")
 */
class UserLotteryLog extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\DataUserLotteryLog();
        
    }

    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParams();
            $count = $this->model
                ->where($where)
                ->with(['user','store'])
                ->where(['win'=>1,'status'=>1])
                ->count();
            $list  = $this->model
                ->where($where)
                ->with(['user','store'])
                ->page($page, $limit)
                ->where(['win'=>1,'status'=>1])
                ->order($this->sort)
                ->select();
            $data  = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }



    public function prize($id)
    {
        $row = $this->model->find($id);
        empty($row) && $this->error('数据不存在');
        if ($this->request->isPost()) {
            $post = $this->request->post();
            $rule = [];
            $this->validate($post, $rule);
            try {
                $post['status'] = 2;
                $save = $row->save($post);
            } catch (\Exception $e) {
                $this->error('保存失败');
            }
            $save ? $this->success('保存成功') : $this->error('保存失败');
        }
        $this->assign('row', $row);
        return $this->fetch();
    }

    public function info($id)
    {
        $row = DataUserReal::where(['lottery_id'=>$id])->find();
        empty($row) && $this->error('用户未上传');
        $this->assign('row', $row);
        return $this->fetch();
    }




    
}